package online.chazi.bootplus.commons.utils.codec;

/**
 * 说明：作者很懒，什么都没留下
 * Created by 叉子同学 on 2020-05-02 02:01
 */
public class LongUtils {

    public static byte[] toByteArray(long values) {
        byte[] buffer = new byte[8];
        for (int i = 0; i < 8; i++) {
            int offset = 64 - (i + 1) * 8;
            buffer[i] = (byte) ((values >> offset) & 0xff);
        }
        return buffer;
    }

    public static long fromBytes(byte[] src) {
        long values = 0;
        for (int i = 0; i < 8 && i < src.length; i++) {
            values <<= 8;
            values |= (src[i] & 0xff);
        }
        return values;
    }

    public static void main(String[] args) {
        for (long i = 222222222220L; i < 222222222230L; i++) {
            byte[] key = toByteArray(i);
            System.out.println("i=" + i + ", key=" + fromBytes(key));
        }
    }

}
